<template>
  <div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="序号" width="180"> </el-table-column>
      <el-table-column prop="realName" label="用户名称" width="180">
      </el-table-column>
      <el-table-column prop="idCard" label="身份证号"> </el-table-column>
      <el-table-column prop="phone" label="手机号"> </el-table-column>
      <el-table-column prop="status" label="审核状态"> </el-table-column>
      <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="pass(scope.row)" v-if="scope.row.status=='0'" type="text" size="small">通过</el-button>
        <el-button @click="prohibit(scope.row)" v-if="scope.row.status=='1'" type="text" size="small">禁止</el-button>
      </template>
    </el-table-column>
    </el-table>

    <br>
    <br>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400">
    </el-pagination>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  data() {
    return {
      tableData: [
        // {
        //   id: "1",
        //   realName: "张三",
        //   idCard: "111111111",
        //   phone: "2222222",
        //   status: "0",
        // },
        // {
        //   id: "1",
        //   realName: "张三",
        //   idCard: "111111111",
        //   phone: "2222222",
        //   status: "0",
        // },
        // {
        //   id: "1",
        //   realName: "张三",
        //   idCard: "111111111",
        //   phone: "2222222",
        //   status: "0",
        // },
        // {
        //   id: "1",
        //   realName: "张三",
        //   idCard: "111111111",
        //   phone: "2222222",
        //   status: "0",
        // },
      ],
      currentPage1: 5,
        currentPage2: 5,
        currentPage3: 5,
        currentPage4: 4
    };
  },
  methods: {
    handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      },
      pass(row) {
        console.log(row);
        axios.put("/admin",{"status":1,"id":row.id},{headers : {'Content-Type' : 'application/json'}}).then(result=>{
            if(result.data.code == 1){
                this.$message('修改成功');
                this.getUser()
            }else{
                this.$message.error('修改失败！');
            }
        })
      },
      prohibit(row) {
        console.log(row);
    
        axios.put("/admin",{"status":0,"id":row.id},{headers : {'Content-Type' : 'application/json'}}).then(result=>{
            if(result.data.code == 1){
                this.$message('修改成功');
                this.getUser()
            }else{
                this.$message.error('修改失败！');
            }
        })
    },
    getUser() {
        axios.get("/admin").then(result=>{
            this.tableData = result.data.data
        })
    }
    },
    mounted() {
        this.getUser();
    }
};
</script>

<style scoped>
</style>